home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / SYS_TOOL / PORTS / PORTS.ZIP / portage.pas < prev    next >
Pascal/Delphi Source File  |  1996-06-27  |  2KB  |  87 lines

  1. unit portage;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, Tports;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     port1: Tport;
  12.     Button1: TButton;
  13.     Edit1: TEdit;
  14.     Edit2: TEdit;
  15.     Label1: TLabel;
  16.     Label2: TLabel;
  17.     Button2: TButton;
  18.     procedure Button1Click(Sender: TObject);
  19.     procedure Button2Click(Sender: TObject);
  20.   private
  21.     { Private declarations }
  22.   public
  23.     procedure Delay(msecs:integer);
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.DFM}
  32. procedure TForm1.Delay(msecs:integer);
  33. var
  34.    FirstTickCount:longint;
  35. begin
  36.      FirstTickCount:=GetTickCount;
  37.      repeat    
  38.            Application.ProcessMessages; {allowing access to other 
  39.                                          controls, etc.}
  40.      until ((GetTickCount-FirstTickCount) >= Longint(msecs));
  41. end;
  42.  
  43. procedure TForm1.Button1Click(Sender: TObject);
  44. var
  45.    freq : integer;
  46.    dura : integer;
  47.    cont : integer;
  48.    h : word;
  49. begin
  50.  
  51. freq := strtoint(edit1.text);
  52.  
  53. with port1 do
  54.      begin
  55.           Address := $43; // Prepare timer by sending 10111100 to port 43.
  56.           data := $B6;
  57.           writetoport;
  58.           address := $42; //Divide input frequency by timer ticks per second and
  59.           freq := word(1193180 div freq);  //* write (byte by byte) to timer.
  60.           data := freq;
  61.           writetoport;
  62.           address := $42;
  63.           data := freq shr 8 ;
  64.           writetoport;
  65.           cont := readfromport; // Save speaker control byte.
  66.           address := $61; // Turn on the speaker (with bits 0 and 1).
  67.           data := (cont or $3);
  68.           writetoport;
  69.           delay(strtoint(edit2.text));
  70.           if boolean(freq) then // Turn speaker back on if necessary.
  71.              begin
  72.                   address := $61;
  73.                   data := cont;
  74.                   writetoport;
  75.           end; // end if
  76.  
  77.      end; // end with
  78.  
  79. end; // end procedure
  80.  
  81. procedure TForm1.Button2Click(Sender: TObject);
  82. begin
  83.      Close;
  84. end;
  85.  
  86. end.
  87.